package com.yjhh.chdataservice.controller;

import com.yjhh.chdataservice.beans.*;
import com.yjhh.chdataservice.except.YJHHException;
import com.yjhh.chdataservice.service.FZJCPlacementPointService;
import com.yjhh.chdataservice.util.CommonResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by hlantian on 2017/9/26.
 */
@Api(tags = "安置点模块相关接口")
@RestController
@RequestMapping(value = "/service/fzjc/point")
@Log4j2
public class FZJCPlacementPointController {

    @Autowired
    private FZJCPlacementPointService fzjcPlacementPointService;


    @ApiOperation(value = "根据省、市行政区划编码获取下级行政区划安置点统计信息", notes = "根据省、市行政区划编码获取下级行政区划安置点统计信息")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPointStaticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<PointStaticsInfoVo>> getPointStaticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<PointStaticsInfoVo>> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = fzjcPlacementPointService.getPointStaticsByAreaCode(areaCode);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPointStaticsByAreaCode", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }
    
    @ApiOperation(value = "根据省、市行政区划编码获取下级行政区划安置点统计信息", notes = "根据省、市行政区划编码获取下级行政区划安置点统计信息")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPointScaleStaticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<PointScaleStaticsInfoVo>> getPointScaleStaticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<PointScaleStaticsInfoVo>> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = fzjcPlacementPointService.getPointScaleStaticsByAreaCode(areaCode);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPointScaleStaticsByAreaCode", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "根据县级行政区划编码获取安置点列表信息", notes = "根据县级行政区划编码获取安置点列表信息")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementPointListByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<PlacementPointSimpleVo>> getPlacementPointListByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<PlacementPointSimpleVo>> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getPlacementPointListByAreaCode(areaCode);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementPointListByAreaCode", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "根据安置点ID获取安置点详细信息", notes = "根据安置点ID获取安置点详细信息")
    @ApiImplicitParam(name = "pointId", value = "安置点ID", required = true, paramType = "query", dataType = "String", defaultValue = "1d3705db-46c1-4449-a515-fce6a3fb83cc")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementPointDetailByPointId", method = RequestMethod.GET)
    public CommonResultData<PlacementPointDetailVo> getPlacementPointDetailByPointId(@RequestParam String pointId) {
        CommonResultData<PlacementPointDetailVo> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getPlacementPointDetailByPointId(pointId);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementPointDetailByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "根据行政区划返回中小学、幼儿园、卫生院所、活动室、其他的个数", notes = "根据行政区划返回中小学、幼儿园、卫生院所、活动室、其他的个数")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementPointServicesStatisticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<PlacementPointServiceStatisticsVo> getPlacementPointServicesStatisticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<PlacementPointServiceStatisticsVo> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getPlacementPointServicesStatisticsByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementPointServicesStatisticsByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }

    @ApiOperation(value = "根据行政区划返回下属区域国家、省年计划安置点数目", notes = "根据行政区划返回下属区域国家、省年计划安置点数目")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementPointYearPlanByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<PlacementPointPlanVo>> getPlacementPointYearPlanByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<PlacementPointPlanVo>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getPlacementPointYearPlanByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementPointYearPlanByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }

    @ApiOperation(value = "根据行政区划返回所属范围内的所有安置点的就业岗位安置情况", notes = "根据行政区划返回所属范围内的所有安置点的就业岗位安置情况")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getJYGWInfoByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<TPJYPostTypeInfoVo>> getJYGWInfoByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<TPJYPostTypeInfoVo>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getJYGWInfoByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getJYGWInfoByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }

    @ApiOperation(value = "根据行政区划返回所属范围内的安置点的开工和入住情况", notes = "根据行政区划返回所属范围内的安置点的开工和入住情况")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPointStartedAndMoveInStatisticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<PlacementPointStartedAndMoveInVo> getPointStartedAndMoveInStatisticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<PlacementPointStartedAndMoveInVo> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getPointStartedAndMoveInStatisticsByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPointStartedAndMoveInStatisticsByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }

    @ApiOperation(value = "根据行政区划和返回所属范围内的安置点列表", notes = "根据行政区划返回所属范围内的安置点列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue =
                    "610000000000"),
            @ApiImplicitParam(name = "areaType", value = "区域类型（陕南，陕北，关中），空字符串表示全部", required = false, paramType = "query", dataType = "String",
                    defaultValue =
                    ""),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getAllPlacementPointByAreaCodeAndAreaType", method = RequestMethod.GET)
    public CommonResultData<List<PlacementPointSimpleInfoVo>> getAllPlacementPointByAreaCode(@RequestParam String areaCode,@RequestParam(required = false) String
            areaType) {
        CommonResultData<List<PlacementPointSimpleInfoVo>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getAllPlacementPointByAreaCode(areaCode,areaType);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getAllPlacementPointByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }

    @ApiOperation(value = "根据安置点ID获取搬迁返回安置点村子和人数", notes = "根据安置点ID获取搬迁返回安置点村子和人数")
    @ApiImplicitParam(name = "pointId", value = "安置点ID", required = true, paramType = "query", dataType = "String", defaultValue = "e02cc01e-a072-4c38-9f32-6738f7c0d415")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getMoveInPointVillageAndPeopleCountByPointId", method = RequestMethod.GET)
    public CommonResultData<PointVillageAndPeopleVo> getMoveInPointVillageAndPeopleCountByPointId(@RequestParam String pointId) {
        CommonResultData<PointVillageAndPeopleVo> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getMoveInPointVillageAndPeopleCountByPointId(pointId);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getMoveInPointVillageAndPeopleCountByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

}
